package ch15;

import java.util.Objects;

public class BankAccountSet {
    private String no;
    private String name;
    private String idCard;
    private String city;

    public BankAccountSet() {
    }

    public BankAccountSet(String no, String name, String idCard, String city) {
        this.no = no;
        this.name = name;
        this.idCard = idCard;
        this.city = city;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

   /* @Override//账号no相同，则认为账号相同
    public boolean equals(Object obj) {//在此处重写list对象的equals方法
        if (obj instanceof BankAccountSet) {
            BankAccountSet b = (BankAccountSet) obj;
            if (this.no == null) {
                if (b.getNo() == null) {
                    return true;
                }
            } else {
                return this.no.equals(b.getNo());
            }
        }
        return false;
    }

    @Override//set需要重写hashCode（）方法
    public int hashCode() {//没有重写之前，对象的hashCode的值情况如下：（两者都是new的新的对象所以hashCode就不一样了）
        //根据nolai比较，no来算hashCode..
        return no==null?0:no.hashCode();
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BankAccountSet that = (BankAccountSet) o;
        return Objects.equals(no, that.no);
    }

    @Override
    public int hashCode() {
        return Objects.hash(no);
    }

    @Override
    public String toString() {
        return "账号{" +
                "no='" + no + '\'' +
                ", name='" + name + '\'' +
                ", idCard='" + idCard + '\'' +
                ", city='" + city + '\'' +
                '}';
    }
}
